
#ifndef WF_GRAPHICVIEW_H
#define WF_GRAPHICVIEW_H

#include <qwidget.h>
#include <qlabel.h>
#include <qscrollbar.h>
#include <qpixmap.h>
#include <qlayout.h>
#include <q3url.h>
#include <q3filedialog.h>
//Added by qt3to4:
#include <QResizeEvent>
#include <Q3GridLayout>
#include <QWheelEvent>
#include <QEvent>
#include <QMouseEvent>
#include <QTabletEvent>
#include <QKeyEvent>
#include <QPaintEvent>
#include <QFocusEvent>

#include "pf_graphicview.h"
#include "pf_layerlistobserver.h"
#include "pf_blocklistobserver.h"
#include "pf_painter.h"
#include "lx_String.h"

#include "ui_scrollbar.h"
#include "gui_export.h"



/**
 * This is the Qt implementation of a widget which can view a 
 * graphic. 
 *
 * Instances of this class can be linked to layer lists using
 * addLayerListListener().
 */
class GUI_EXPORT WF_GraphicView: public QWidget,
            public PF_GraphicView,
			public Q3FilePreview,
            public PF_LayerListObserver,
    public PF_BlockListObserver {
    Q_OBJECT

public:
    WF_GraphicView(QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
    virtual ~WF_GraphicView();

    virtual int getWidth();
    virtual int getHeight();
	virtual void redraw(LX_Define::RedrawMethod method=LX_Define::RedrawAll);
    virtual void adjustOffsetControls();
    virtual void adjustZoomControls();
    virtual void setBackground(const PF_Color& bg);
    virtual void setMouseCursor(LX_Define::CursorType c);
        virtual void updateGridStatusWidget(const QString& text);

		virtual	QPixmap* getPixmapForView(QPixmap *pm);
		
    // Methods from PF_LayerListObserver Interface:
    virtual void layerEdited(PF_Layer*) {
        redraw(LX_Define::RedrawDrawing); 
    }
    virtual void layerRemoved(PF_Layer*) {
        redraw(LX_Define::RedrawDrawing); 
    }
    virtual void layerToggled(PF_Layer*) {
        redraw(LX_Define::RedrawDrawing); 
    }

protected:
    virtual void emulateMouseMoveEvent();
    virtual void mousePressEvent(QMouseEvent* e);
    virtual void mouseReleaseEvent(QMouseEvent* e);
    virtual void mouseMoveEvent(QMouseEvent* e);
	virtual void tabletEvent(QTabletEvent* e);
    virtual void leaveEvent(QEvent*);
    virtual void enterEvent(QEvent*);
    virtual void focusInEvent(QFocusEvent*);
    virtual void focusOutEvent(QFocusEvent*);
    virtual void wheelEvent(QWheelEvent* e);
    virtual void keyPressEvent(QKeyEvent* e);
    virtual void keyReleaseEvent(QKeyEvent* e);

    void paintEvent(QPaintEvent *);
    virtual void resizeEvent(QResizeEvent* e);

	void previewUrl(const Q3Url &u);

private slots:
    void slotHScrolled(int value);
    void slotVScrolled(int value);

protected:
    //! Horizontal scrollbar.
    UI_ScrollBar* hScrollBar;
    //! Vertical scrollbar.
    UI_ScrollBar* vScrollBar;
    //! Layout used to fit in the view and the scrollbars.
    Q3GridLayout* layout;
	//! Label for grid spacing.
	QLabel* gridStatus;
    //! CAD mouse cursor
    QCursor* curCad;
    //! Delete mouse cursor
    QCursor* curDel;
    //! Select mouse cursor
    QCursor* curSelect;
    //! Magnifying glass mouse cursor
    QCursor* curMagnifier;
    //! Hand mouse cursor
    QCursor* curHand;
		
	// Used for buffering different paint layers
	QPixmap *PixmapLayer1;  // Used for grids and absolute 0
	QPixmap *PixmapLayer2;  // Used for teh actual CAD drawing
	QPixmap *PixmapLayer3;  // USed for crosshair and actionitems
	
	LX_Define::RedrawMethod redrawMethod;
		
};

#endif
